package com.hong.redis.redisex;


import java.util.ArrayList;

public class RedisClient {
    public static void main(String[] args) throws InterruptedException {


        System.out.println("测试向集合中插入数据，并设置过期时间");
        RedisUtil.setVal2List("s1",30 * 1000 , "k1" , "k2","k2");
        RedisUtil.setVal2List("s1",3 * 1000 , "k3" , "k4","k5");
        RedisUtil.setVal2List("s1", "k6");
        System.out.println("数据插入成功，集合中的数据有:");
        ArrayList<String> range = RedisUtil.getRange("s1", 0, -1);
        for(String s1 : range){
            System.out.print(s1 + " ");
        }
        System.out.println();
        System.out.println("测试根据下标获取对应的元素");
        String s1 = RedisUtil.getValFromListByIndex("s1", 1);
        System.out.println(s1);
        String s2 = RedisUtil.getValFromListByIndex("s1", 3);
        System.out.println(s2);
        // 下标越界的元素
        String s3 = RedisUtil.getValFromListByIndex("s1", 10);
        System.out.println(s3);


        System.out.println("测试根据下标修改元素的key值或者过期时间");
        RedisUtil.setNewValByIndex("s1",0,"k00");
        RedisUtil.setNewValByIndex("s1",1,1500);
        RedisUtil.setNewValByIndex("s1",2,"k0101",1500);
        System.out.println("此时元素有：");
        ArrayList<String> range0 = RedisUtil.getRange("s1", 0, -1);
        for(String s : range0){
            System.out.print(s + " ");
        }
        System.out.println();
        System.out.println("1.6s后..");
        Thread.sleep(1600);
        ArrayList<String> range1 = RedisUtil.getRange("s1", 0, -1);

        for(String s : range1){
            System.out.print(s + " ");
        }
        System.out.println();
        System.out.println("删除指定的value元素");
        RedisUtil.removeVal("s1","k00");
        ArrayList<String> range2 = RedisUtil.getRange("s1", 0, -1);
        for(String s : range2){
            System.out.print(s + " ");
        }
    }

}
